package com.cssw.fyzb.busi.api.acct;

import com.cssw.fyzb.busi.service.acct.AcctService;
import com.cssw.fyzb.core.model.dodb.Acct;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



/**
 * @Author zhouxu
 * @create 2020-12-24 21:46
 */
@Function(description = "账本余额查询", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户ID", required = true),
        @Parameter(name = "acctType", type = Type.String, description = "账本类别 F Y G", required = true)
})
@Component
public class QueryAcctBalance implements Action {
    @Autowired
    private AcctService acctService;

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        String acctType = request.getString("acctType");

        Acct acct = acctService.queryAcctByUIdAndType(userId, acctType);
        if (!acctType.equals( "G")) {
            acct.setBalanceFee(acct.getBalanceFee().setScale(2));
        } else {
            acct.setBalanceFee(acct.getBalanceFee().setScale(7));
        }
        return Response.success().put("data", acct);
    }
}
